﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

public partial class KMrpt14 : ExtBaseRpt
{
    string mid;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            BuildGridPanel(this.GridPanel1, mid, Session["UserID"].ToString());
            this.txtarea.GetStore().DataSource = db.DM_GetDateSet("select OperationAreaID,OperationAreaName from Bas_OperationArea");
            txtstock.GetStore().DataSource = db.DM_GetDateSet("select stockid,stockname from Bas_stock");
            this.txtseason.GetStore().DataSource = mydb.DM_GetDateSet("select distinct seasonname from v_mat");
            this.txtyear.GetStore().DataSource = mydb.DM_GetDateSet("select distinct yearno from v_mat order by yearno");
            this.txtmatkind.GetStore().DataSource = mydb.DM_GetDateSet("select distinct kindname from v_mat");
            this.txtbdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString();
            //this.txtbjhdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            //this.txtejhdate.Text = DateTime.Now.ToString();
        }
    }
    [DirectMethod(Namespace = "CompanyX")]
    public void binStock(string area)
    {
        //ShowBox(area);
        //string[] str = area.Split(',');
        //string p ="";
        //foreach (string s in str)
        //{
        //    p += "'" + s + "',";
        //}
        //p = p.TrimEnd(',');
        if (area == "[]")
            return;
        area = area.Replace("[", "");
        area = area.Replace("]", "");
        area = area.Replace("\"", "'");

        string sql = @"select stockid,stockname from bas_stock where operationareaid in (" + area + ") order by stockname";
        //ShowBox(sql);
        this.txtstock.GetStore().DataSource = db.DM_GetDateSet(sql);
        this.st_stock.DataBind();
    }
    [DirectMethod(Namespace = "CompanyX")]
    public void CreateStock()
    {
        StoreColumns(this.Store1, mid, "GridView1");
    }
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        string bdate, edate;
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            bdate = "";
        else
            bdate = txtbdate.Text;

        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtedate.Text;

        //if (Convert.ToDateTime(txtbjhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        //    sjhdaate = "";
        //else
        //    sjhdaate = txtbjhdate.Text;

        //if (Convert.ToDateTime(txtejhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
        //    ejhdaate = "";
        //else
        //    ejhdaate = txtejhdate.Text;

        string stock = StrSplitParam(txtstock);
        string season = StrSplitParam(this.txtseason);
        string yearno = StrSplitParam(this.txtyear);
        string matkind = StrSplitParam(this.txtmatkind);
        string areas = StrSplitParam(txtarea);
        string zt = (pathchk.Checked==true ? "1":"0");
        this.Store1.DataSource = mydb.DM_GetDateSet("KM_StockByMatSeriesRpt '" + bdate + "','" + edate + "','" + areas + "','" + stock + "','" + season + "','" + yearno + "','" + matkind + "'," + zt);
        this.Store1.DataBind();
    }


    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid,"xls",e.Xml,this.Response,this.Title);
    }
}